var express = require('express');
var router = express.Router();
var md5 = require('md5');
const crypto = require('crypto');

var db = require("./../utils/db.js");

/* GET home page. */
router.get('/', function (req, res, next) {
    res.redirect('/login');
});
/* GET home page. */
router.get('/index', function (req, res, next) {
    var loginedUser = req.session.loginedUser;

    if (!loginedUser) {
        res.send("请登录" + err);
    } else {
        req.session.loginedUser = loginedUser;
        res.render('index', {
            title: '工作台'
        });
    }

});

/* GET home page. */
router.get('/testPasteImage', function (req, res, next) {
    res.render('testPasteImage', {
        title: '工作台'
    });

});

/* MD5工具页面. */
router.get('/mdPage', function (req, res, next) {
    var loginedUser = req.session.loginedUser;
    if (!loginedUser) {
        res.send("请登录" + err);
    } else {
        res.render('admin/tool/mdFive', {
            title: 'MD5小工具'
        });
    }

});

/**
 * md5解密
 */
router.post("/decrypt",function(req,res,next){
    var decrypted = req.body.hash;
    console.log(md5(decrypted));
    var encryption =md5(decrypted);
    return encryption;
});

/**
 * 朴素贝叶斯展示
 */
router.get('/bayes', function (req, res, next) {
    var loginedUser = req.session.loginedUser;
    if (!loginedUser) {
        res.send("请登录" + err);
    } else {
        res.render('bayes', {
        });
    }

});





module.exports = router;
